﻿
Partial Class WebForm_ManageEnlistRecord_AddEnlistRecord
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
        End If
    End Sub

    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click

        'ObjectDataSource2.SelectParameters.Item("Region").DefaultValue = VolunteerQueryControl1.Region
        'ObjectDataSource2.SelectParameters.Item("Region2").DefaultValue = VolunteerQueryControl1.Region2
        ObjectDataSource2.SelectParameters.Item("UOrganizationID").DefaultValue = VolunteerQueryControl1.OrganizationID
        ObjectDataSource2.SelectParameters.Item("VOrganizationID").DefaultValue = VolunteerQueryControl1.VOrganizationID
        ObjectDataSource2.SelectParameters.Item("VolunteerId").DefaultValue = VolunteerQueryControl1.VolunteerId
        ObjectDataSource2.SelectParameters.Item("VolunteerName").DefaultValue = VolunteerQueryControl1.VolunteerName
        ObjectDataSource2.SelectParameters.Item("TEL").DefaultValue = VolunteerQueryControl1.VolunteerTEL
        ObjectDataSource2.SelectParameters("EnlistID").DefaultValue = gv.SelectedValue
        Me.ObjectDataSource2.SelectParameters("TrainingWHour").DefaultValue = Me.txtTrainingBHour.Text.Replace("'", "''")

        GridView_Volunteers.DataSourceID = ObjectDataSource2.ID
        GridView_Volunteers.DataBind()

    End Sub

    Protected Sub gv_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            If TypeOf DataBinder.Eval(e.Row.DataItem, "QueryAccess") Is DBNull OrElse DataBinder.Eval(e.Row.DataItem, "QueryAccess") = "N" Then
                TryCast(e.Row.FindControl("LinkButton1"), LinkButton).Visible = False
            ElseIf DataBinder.Eval(e.Row.DataItem, "QueryAccess") = "Y" Then
                TryCast(e.Row.FindControl("LinkButton1"), LinkButton).Visible = True
            End If
        End If
    End Sub

    Protected Sub gv_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gv.SelectedIndexChanged
        GridView_Volunteers.DataSourceID = ""

    End Sub

    Public Event Finish(ByVal sender As Object, ByVal e As System.EventArgs)

    Protected Sub btnGetIn_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim enlistID As String = Me.gv.SelectedValue

        If enlistID Is Nothing Then
            MyObj.ShowMessage("未選擇招募活動")
        Else

            Dim dat As New clsData
            Dim sql As New MyStringBuilder

            Dim CheckBox1 As CheckBox

            For i As Integer = 0 To GridView_Volunteers.Rows.Count - 1
                CheckBox1 = TryCast(Me.GridView_Volunteers.Rows(i).FindControl("CheckBox1"), CheckBox)

                If Not CheckBox1 Is Nothing AndAlso CheckBox1.Checked Then
                    sql.AppendFormat("insert EnlistRecordApplication select ")
                    sql.AppendFormat("'{0}' ", enlistID)
                    sql.AppendFormat(",'{0}' ", GridView_Volunteers.DataKeys(i).Value)
                    sql.AppendFormat(",{0} ", "null")
                    '09.11.12 不需審核改為直接錄取
                    sql.AppendFormat(",'AP'")
                    sql.AppendFormat(",{0} ", "getdate()")
                    sql.AppendFormat(",'{0}' ", clsAuth.GetUserID())

                    '09.11.12 不需審核改為直接錄取
                    sql.AppendFormat("insert into EnlistRecord(EnlistID,VolunteerID,Active,CreateDate,CreateBy) values(")
                    sql.AppendFormat("'{0}'", enlistID)
                    sql.AppendFormat(",'{0}'", GridView_Volunteers.DataKeys(i).Value)
                    sql.AppendFormat(",'Y'")
                    sql.AppendFormat(",{0}", "getdate()")
                    sql.AppendFormat(",'{0}'", clsAuth.GetUserID())
                    sql.AppendFormat(")")
                End If

            Next

            If sql.Length = 0 Then
                MyObj.ShowMessage(Me.GetLocalResourceObject("MustCheck"))
            Else
                Using scope As New Transactions.TransactionScope
                    dat.AccData(sql.ToString(), Nothing, Data.CommandType.Text)
                    scope.Complete()
                End Using
                Me.gv.DataBind()
                RaiseEvent Finish(Me, New EventArgs)
            End If

        End If

    End Sub

End Class
